﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;

namespace Ewts.BaseData
{
    public partial class CityModify : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(id);
                }
            }
        }

        private void ShowInfo(int id)
        {
            DataLib.BLL.City bll = new DataLib.BLL.City();
            DataLib.Model.City model = bll.GetModel(id);
            this.lblid.Text = model.id.ToString();
            //this.txtcompanyid.Text = model.companyid.ToString();
          
            this.txtcityname.Text = model.cityname;
            this.txtprovince.Text = model.province;
            this.txtstate.Text = model.state;
            //this.ddlflag1.SelectedValue = model.flag1;
            this.txtmemo.Text = model.memo;
        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            //if (this.txtcompanyid.Text.Trim().Length == 0)
            //{
            //    strErr += "公司ID不能为空！\\n";
            //}
            //if (this.txtcitycode.Text.Trim().Length == 0)
            //{
            //    strErr += "城市编码不能为空！\\n";
            //}
            if (this.txtcityname.Text.Trim().Length == 0)
            {
                strErr += "城市名称不能为空！\\n";
            }
            if (this.txtprovince.Text.Trim().Length == 0)
            {
                strErr += "所属省份不能为空！\\n";
            }
            if (this.txtstate.Text.Trim().Length == 0)
            {
                strErr += "国家不能为空！\\n";
            }  
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int id = int.Parse(this.lblid.Text);

           // string companyid = this.txtcompanyid.Text;
       
            string cityname = this.txtcityname.Text;
            string province = this.txtprovince.Text;
            string state = this.txtstate.Text;
            string memo = this.txtmemo.Text;
            //string flag1 = this.ddlflag1.SelectedValue;


            DataLib.Model.City model = new DataLib.Model.City();
            model.id = id;

           // model.companyid = int.Parse(companyid);
            model.cityname = cityname;
            model.province = province;
            model.state = state;
            model.memo = memo;
            //model.flag1 = flag1;

            DataLib.BLL.City bll = new DataLib.BLL.City();
            bll.Update(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "CityList.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("CityList.aspx");
        }
    }
}